#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>

using namespace std;

class CC{
public:
    static CC *&getInstance(){
        if(!p){
            p=new CC();
        }
        return p;
    }

    static void destory(){
        if(p){
            cout<<"destory"<<endl;
            delete p;
            p=nullptr;
        }
        
    }


private:
    int a;
    static CC *p;
    CC():a(2){}
    ~CC(){
        cout<<"~~~"<<endl;
    }
    CC(const CC &rhs)=delete;


};
CC *CC::p =nullptr;


int main()
{
    CC* &c1 = CC::getInstance();
    CC* &c2 = CC::getInstance();
    if(c1) cout<<"ok"<<endl;
    cout<<c1<<endl;
    cout<<c2<<endl;
    CC::destory();
    CC::destory();
    if(!c1) cout<<"safe"<<endl;
    return 0;
}

